﻿namespace NTLib.Pipe.Descriptors
{
    using Core.Descriptors;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    /// <summary>
    /// Base class used to implement the common behavior of a <see cref="ITargetDescriptor"/>
    /// </summary>
    /// <seealso cref="NTLib.Core.Descriptors.Descriptor" />
    /// <seealso cref="NTLib.Pipe.Descriptors.ITargetDescriptor" />
    public class BaseTargetDescription : Descriptor, ITargetDescriptor
    {
        #region Ctor

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseTargetDescription"/> class.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="name">The name.</param>
        public BaseTargetDescription(Guid id, string name = null)
            : base(id, name)
        {
        }

        #endregion

        #region Methods

        /// <summary>
        /// Equalses the specified other.
        /// </summary>
        public bool Equals(ITargetDescriptor other)
        {
            if (!base.Equals((IDescriptor)other))
            {
                return false;
            }

            return OnEquals(other);
        }

        /// <summary>
        /// Called when the <see cref="Equals(ITargetDescriptor)"/> method is called.
        /// All the basic check have already been check when the <see cref="OnEquals(ITargetDescriptor)"/>
        /// is called.
        /// </summary>
        protected virtual bool OnEquals(ITargetDescriptor other)
        {
            return true;
        }

        #endregion
    }
}
